﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace DrPetShop.Web
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            DateTime timeStart = DateTime.Now;
            DrPetShop.Web.Unit.Loger.WriteSysLog("Application_Start #########################");

            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            try
            {
                //Log4Net初始化
                log4net.Config.XmlConfigurator.Configure();

                //初始化多语言
                DrPetShop.Web.Unit.MultiLanguage.GetLang("shop");

                //初始化数据库数据
                DrPetShop.Web.DAL.ProductDAL.ResetProductCache();
                DrPetShop.Web.DAL.ClassTypeDAL.ResetClassTypeCache();
                DrPetShop.Web.DAL.ProductClassTypeDAL.ResetProductClassCache();
                DrPetShop.Web.DAL.RegionCodeDAL.ResetRegionCodeCache();
                DrPetShop.Web.DAL.LinkDAL.ResetLinkCache();
                DrPetShop.Web.DAL.AdvertDAL.ResetAdvertCache();
            }
            catch (Exception e)
            {
                DrPetShop.Web.Unit.Loger.WriteSysErr(e, "Application_Start");
            }

             //计算自定义初始化时间
            DrPetShop.Web.Unit.Loger.WriteSysLog("Application_Start_Time:" + DateTime.Now.Subtract(timeStart).TotalSeconds.ToString());
        }
    }
}